define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-edit").data("area", ["50%", "50%"]);//编辑
            $(".btn-add").data("area", ["50%", "50%"]); //添加
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/user_card_orders/index' + location.search,
                    add_url: 'order/user_card_orders/add',
                    edit_url: 'order/user_card_orders/edit',
                    del_url: 'order/user_card_orders/del',
                    multi_url: 'order/user_card_orders/multi',
                    import_url: 'order/user_card_orders/import',
                    table: 'user_card_orders',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'user.nickname', title: __('下单用户'), operate: 'LIKE'},
                        {field: 'card.type', title: __('会员类型'),
                            searchList: {1: __('豪华会员'), 2: __('SVIP会员')},
                            formatter: Table.api.formatter.label
                        },
                        {field: 'card.name', title: __('购买会员'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'params', title: __('会员权益'), operate: 'LIKE', formatter: function (value, index) {
                                return '人脉显示:' + value.number + '/个|查看数量：' + value.look_number + '/次|附件容量：' + value.file_capacity + 'MB';
                            }
                        },
                        {field: 'card.original_price', title: __('Card.original_price'), operate:'BETWEEN'},
                        {field: 'card.sales_price', title: __('Card.sales_price'), operate:'BETWEEN'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'status', title: __('支付状态'),
                            searchList: {1: __('待支付'), 2: __('支付成功'), 3: __('支付失败')},
                            formatter: Table.api.formatter.label
                        },
                        {field: 'isExpire', title: __('是否到期'),
                            formatter: Table.api.formatter.label
                        },
                        {field: 'expire_date', title: __('Expire_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'pay_time', title: __('支付时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            table.on('post-body.bs.table', function () {
                $(".btn-editone").data("area", ["50%", "50%"]);
                $(".btn-addone").data("area", ["50%", "50%"]);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
